package com.luoke.handler.request;

import com.luoke.connect.GameWebSocketClient;
import com.luoke.service.request.UserRequestService;
import com.luoke.service.request.impl.UserRequestServiceImpl;

import java.util.Scanner;

import static javafx.application.Platform.exit;

/**
 * 用户请求处理层,负责请求的分发
 */
public class UserRequestHandler {

    private UserRequestService userRequestService = new UserRequestServiceImpl();


    /**
     * 展示登录菜单
     * @param gameWebSocketClient 使用该对象与服务端通信
     */
    public void showLoginMenu(GameWebSocketClient gameWebSocketClient) {
        Scanner scanner = new Scanner(System.in);
        int choose;
        while (true){
            System.out.println("===== 欢迎来到洛克宠物对战游戏 =====");
            System.out.println("1. 登录");
            System.out.println("2. 注册");
            System.out.println("3. 退出");
            System.out.print("请输入您的选择: ");
            choose = scanner.nextInt();
            scanner.nextLine();//删除换行符
            if (choose >= 1 && choose <= 3) {
                break;
            }
            System.out.println("无效选择，请重新输入。");
        }
        switch (choose) {
            case 1:
                userRequestService.login(gameWebSocketClient, scanner);
                break;
            case 2:
                userRequestService.register(gameWebSocketClient, scanner);
                break;
            case 3:
                exit();
                break;
            default:
                System.out.println("无效的选择，请重新输入。");
                break;

        }
    }





}
